<?php
class uploader
{
    static function uploadProfPic($username)
    {
        require_once ('database.php');
        database::query("UPDATE user SET profpic = (SELECT IDFOTO FROM `foto` WHERE Username = '$username' ORDER BY TglUpload LIMIT 1) WHERE Username = '$username'");
        uploader::uploadFoto($username);
    }

    static function uploadFoto($path){
        if ($_FILES["foto"]["error"] > 0)
        {
            echo "Return Code: " . $_FILES["foto"]["error"] . "<br />";
        }
        else
        {
            if (file_exists("../".$path))
            {
                echo $_FILES["foto"]["name"] . " already exists. ";
            }
            else
            {
                move_uploaded_file($_FILES["foto"]["tmp_name"], "../".$path);
                //echo "Stored in: " . "users/".$path .'<br/>';
            }
        }
    }

}
?>
